//
// Created by fanghr on 18-3-22.
//

#ifndef CSSL2CPP_CSSL2CPP_H
#define CSSL2CPP_CSSL2CPP_H

#include "cssl.h"
#include <string>
#include <list>

#define DEFAULT_PATH "/dev/ttyUSB0"
#define DEFAULT_CALLBACK_FUNC nullptr
#define DEFAULT_ID 0
#define DEFAULT_BAUD 9600
#define DEFAULT_PARITY 0
#define DEFAULT_BITS 8
#define DEFAULT_STOP 0

class cssl {
private:
    cssl_t *serial;
public:
    explicit cssl(std::string path = DEFAULT_PATH, cssl_callback_t cb = DEFAULT_CALLBACK_FUNC, int id = DEFAULT_ID,
                  int baud = DEFAULT_BAUD, int bits = DEFAULT_BITS, int parity = DEFAULT_PARITY,
                  int stop = DEFAULT_STOP);

    ~cssl();

    void close();

    void setup(int baud, int bits, int parity, int stop);

    void setflowcontrol(int rtscts, int xonxoff);

    void flush();

public:

    static void start();

    static void stop();

    static int get_err();

    static const std::string get_err_str();

public:
    void putchar(char ch);

    void putdata(uint8_t *arr, size_t len);

    void putdata(std::list<uint8_t> &vec);

    void putstring(const std::string &str);

    void putstring(const char *str);

public:
    void settimeout(unsigned int);

    uint8_t getchar();

    int getdata(uint8_t *buffer, int size);

    int getdata(std::list<uint8_t> &buffer, int size);
};

//class null_pointer_exception {
//public:
//   null_pointer_exception() {}
//};

#endif //CSSL2CPP_CSSL2CPP_H
